package fr.auzaiphe.admin.view;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import fr.auzaiphe.admin.constantes.ConstantesAdmin;
import fr.auzaiphe.admin.model.Evenement;
import fr.auzaiphe.admin.model.EvtEchangeTemps;

/**
 * Champs de notification
 * @author Anthony REY
 * @since 21/05/2012
 */
public class NotifLabel extends JPanel
{
	private static final Color COLOR_NEW = Color.blue;
	private static final Color COLOR_STD = Color.black;
	private static final Color COLOR_NEW_BACK = Color.white;
	private boolean clicked;
	private boolean viewed;
	private JLabel label;
	private GridBagLayout layout;
	private JButton buttonOui;
	private JButton buttonNon;
	private boolean echangeEffectue;
	
	/**
	 * Créé un champs de notification
	 * @param pEvt L'évènement à traiter
	 */
	public NotifLabel(Evenement pEvt)
	{
		super();
		
		/*
		 * TODO Associer l'état de l'évènement à l'évènement et le gérer autrement qu'avec un booléen puisque la liste se génère sans cesse
		 */
		this.echangeEffectue = false;
		
		this.layout = new GridBagLayout();
		this.setLayout(this.layout);
		GridBagConstraints c = new GridBagConstraints();
		
		this.label = new JLabel(pEvt.toString());
		c.weightx = 0.5;
		c.anchor = GridBagConstraints.WEST;
		
		this.add(this.label, c);
		
		/*
		 * Gestion du temps
		 */
		if(pEvt instanceof EvtEchangeTemps && !this.echangeEffectue)
		{
			this.buttonOui = new JButton(ConstantesAdmin.BOUTON_OUI);
			this.buttonNon = new JButton(ConstantesAdmin.BOUTON_NON);
			this.add(this.buttonOui);
			this.add(this.buttonNon);
			this.echangeEffectue = true;
		}
		
		this.clicked = true;
		this.viewed = false;
	}
	
	/**
	 * Colorie le champ s'il est récent
	 */
	public void setColor()
	{
		this.label.setForeground(COLOR_NEW);
		this.setBackground(COLOR_NEW_BACK);
	}

	/**
	 * @return the clicked
	 */
	public boolean isClicked() 
	{
		return clicked;
	}

	/**
	 * @param clicked the clicked to set
	 */
	public void setClicked() 
	{
		this.clicked = true;
		this.label.setForeground(COLOR_STD);
	}

	/**
	 * @return the viewed
	 */
	public boolean isViewed() 
	{
		return viewed;
	}

	/**
	 * @param viewed the viewed to set
	 */
	public void setViewed() 
	{
		this.viewed = true;
	}
}
